package com.sheep.spark;

import com.sheep.api.bean.ADSBBean;
import com.sheep.api.spark.SparkCommonDao;
import com.sheep.api.spark.SparkCommonService;
import com.sheep.api.util.JAXBUtils;
import com.sheep.api.util.ZipUtil;
import com.sheep.spark.job.FileStreamJob;
import com.sheep.spark.job.impl.ErrorLogAnalysisJobByFile;
import com.sheep.spark.service.impl.SparkCommonImpl;
import com.sheep.spark.util.SparkSupport;

import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 16-5-31
 * Time: 下午3:17
 * To change this template use File | Settings | File Templates.
 */
public class AppMain implements  Serializable {

    public static void main(String[] args){
        SparkSupport.init();
        long start = System.currentTimeMillis();
        SparkCommonService test = new SparkCommonImpl();
        List<ADSBBean> list = test.getADSBList("2016", "05", "31", "B-5938", "MU728");
        long end = System.currentTimeMillis();
        System.out.println("first run time:"+(end - start));
        System.out.println(list.size());
//        try {
//            for(ADSBBean i:list){
//                System.out.println("XML ADSB:"+ JAXBUtils.dtoToXmlString(i));
//            }
//        } catch (JAXBException e) {
//            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
//        }
//        System.out.println("list size:"+list.size());
        start = System.currentTimeMillis();
        List<String> temp  =test.getADSBJson("2016", "05", "31", "B-5938", "MU728");
        end = System.currentTimeMillis();
        System.out.println("second run time:"+(end - start));
        System.out.println("list size:"+temp.size());
//        FileStreamJob job1 = new ErrorLogAnalysisJobByFile("d:\\test1.txt");


        start = System.currentTimeMillis();
        temp  =test.getADSBJson("2016", "05", "31", "B-5659", "MF842");
        end = System.currentTimeMillis();
        System.out.println("second run time:"+(end - start));
        System.out.println("list size:"+temp.size());
        String comp = test.getADSBDataByCompress("2016", "05", "31", "B-5659", "MF842");
        System.out.println(comp);
        try {
            System.out.println(ZipUtil.uncompress(comp));
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
//        FileStreamJob job2 = new ErrorLogAnalysisJobByFile("d:\\test2.txt");
//        list = test.getADSBListByTime("2016", "05", "31", "B-5938", "MU728",1464642605148l,1464648365065l);
//        System.out.println("list size:"+list.size());
//        list  =test.getADSBJsonByTime("2016", "05", "31", "B-5938", "MU728",1464642605148l,1464648365065l);
//        System.out.println("list size:"+list.size());
    }
}
